﻿using System;

namespace UniRx
{
	// Token: 0x020001FE RID: 510
	public sealed class MultipleAssignmentDisposable : IDisposable, ICancelable
	{
		// Token: 0x170000DB RID: 219
		// (get) Token: 0x06000AC0 RID: 2752 RVA: 0x00039214 File Offset: 0x00037614
		public bool IsDisposed
		{
			get
			{
				object obj = this.gate;
				bool result;
				lock (obj)
				{
					result = (this.current == MultipleAssignmentDisposable.True);
				}
				return result;
			}
		}

		// Token: 0x170000DC RID: 220
		// (get) Token: 0x06000AC1 RID: 2753 RVA: 0x0003925C File Offset: 0x0003765C
		// (set) Token: 0x06000AC2 RID: 2754 RVA: 0x000392B4 File Offset: 0x000376B4
		public IDisposable Disposable
		{
			get
			{
				object obj = this.gate;
				IDisposable result;
				lock (obj)
				{
					result = ((this.current != MultipleAssignmentDisposable.True) ? this.current : UniRx.Disposable.Empty);
				}
				return result;
			}
			set
			{
				bool flag = false;
				object obj = this.gate;
				lock (obj)
				{
					flag = (this.current == MultipleAssignmentDisposable.True);
					if (!flag)
					{
						this.current = value;
					}
				}
				if (flag && value != null)
				{
					value.Dispose();
				}
			}
		}

		// Token: 0x06000AC3 RID: 2755 RVA: 0x0003931C File Offset: 0x0003771C
		public void Dispose()
		{
			IDisposable disposable = null;
			object obj = this.gate;
			lock (obj)
			{
				if (this.current != MultipleAssignmentDisposable.True)
				{
					disposable = this.current;
					this.current = MultipleAssignmentDisposable.True;
				}
			}
			if (disposable != null)
			{
				disposable.Dispose();
			}
		}

		// Token: 0x040006F1 RID: 1777
		private static readonly BooleanDisposable True = new BooleanDisposable(true);

		// Token: 0x040006F2 RID: 1778
		private object gate = new object();

		// Token: 0x040006F3 RID: 1779
		private IDisposable current;
	}
}
